import { reqCategoryList, reqFloorList, reqGetBannerList } from "@/api";

const state = {
  categoryList: [],//看后台可知请求返回的是一个数组，定义一个数组好接受返回的数据
  floorList: []
};
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList//保存数据
  },
  GETBANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  GETFLOORLIST(state, floorList) {
    state.floorList = floorList
  }
};
const actions = {
  //要求返回一个promise对象

  async categoryList({ commit }) {//对象结构
    let result = await reqCategoryList();//发送请求
    // console.log(result);

    if (result.code === 200) {

      commit("CATEGORYLIST", result.data)
    }
  },
  //获取首页轮播图数据
  async getBannerList({ commit }) {
    let result = await reqGetBannerList();
    // console.log(result);
    if (result.code == 200) {
      commit('GETBANNERLIST', result.data)
    }

  },
  async getFloorList({ commit }) {
    let result = await reqFloorList();
    if (result.code == 200) {
      commit('GETFLOORLIST', result.data)
    }

  }
};
const getters = {

};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}